package com.itheima.test3;

public class Test3Polymorpic {
    public static void main(String[]args){
        useAnimal(new Dog());
        useAnimal(new Cat());
    }
    public  static void useAnimal(Animal a){
        a.eat();
        //a. watchHome();

        // 判断a变量记录的类型, 是否是Dog
        if(a instanceof  Dog){
            Dog dog=(Dog)a;
            dog.watchHome();
        }
       /* Dog dog=(Dog)a;
        dog.watchHome();*/// ClassCastException  类型转换异常
    }
}
